package org.example.service.impl;

import org.example.mapper.AnnouncementMapper;
import org.example.ourEnum.AnnouncementStatus;
import org.example.pojo.domain.Announcement;
import org.example.service.AnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AnnouncementServiceImpl implements AnnouncementService {

    @Autowired
    private AnnouncementMapper announcementMapper;

    @Override
    public void createDraft(Announcement announcement) {
        announcement.setStatus(AnnouncementStatus.draft);
        announcementMapper.insert(announcement);
    }

    @Override
    public Announcement getById(Integer id) {
        return announcementMapper.selectById(id);
    }

    @Override
    public List<Announcement> getAll() {
        return announcementMapper.selectAll();
    }

    @Override
    public void update(Announcement announcement) {
        announcementMapper.update(announcement);
    }

    @Override
    public void delete(Integer id) {
        announcementMapper.delete(id);
    }

    @Override
    public void changeStatus(Integer id, AnnouncementStatus status) {
        announcementMapper.changeStatusById(id, status);
    }
}